package com.baikeyang.service.administrativeArea.impl;

import com.baikeyang.common.model.AdministrativeArea;
import com.baikeyang.mapper.AdministrativeAreaMapper;
import com.baikeyang.service.administrativeArea.IAdministrativeAreaService;
import com.baikeyang.service.base.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行政区域Service
 */
@Service(value = "administrativeAreaService")
public class AdministrativeAreaServiceImpl extends SuperServiceImpl<AdministrativeAreaMapper, AdministrativeArea> implements IAdministrativeAreaService {

    @Autowired
    AdministrativeAreaMapper administrativeAreaMapper;

    @Override
    public List<AdministrativeArea> getProvinces() {
        QueryWrapper<AdministrativeArea> provincesWrapper = new QueryWrapper<AdministrativeArea>();
        provincesWrapper.eq("level", "1");
        return administrativeAreaMapper.selectList(provincesWrapper);
    }

    @Override
    public List<AdministrativeArea> getCitys(String province) {
        QueryWrapper<AdministrativeArea> provincesWrapper = new QueryWrapper<AdministrativeArea>();
        provincesWrapper.eq("level", "2");
        provincesWrapper.eq("parent_code", province);
        return administrativeAreaMapper.selectList(provincesWrapper);
    }

    @Override
    public List<AdministrativeArea> getDistricts(String cityCode) {
        QueryWrapper<AdministrativeArea> provincesWrapper = new QueryWrapper<AdministrativeArea>();
        provincesWrapper.eq("level", "3");
        provincesWrapper.eq("parent_code", cityCode);
        return administrativeAreaMapper.selectList(provincesWrapper);
    }

    @Override
    public List<AdministrativeArea> getProvinces(AdministrativeArea provinces) {
        QueryWrapper<AdministrativeArea> provincesWrapper = new QueryWrapper<AdministrativeArea>();
        return administrativeAreaMapper.selectList(provincesWrapper);
    }
}
